<?php 
 
	$customerid=Mage::getSingleton('customer/session')->getCustomerId();
	$isPartner= Mage::getModel('marketplaceprofile/marketplaceprofile')->isPartner($customerid);
	if($isPartner==1){?>
<link href="<?php echo $this->getSkinUrl('Customerpartner/css/global.css'); ?>" rel="stylesheet" type="text/css" />
<script type="text/javascript">
if (typeof jQuery == 'undefined'){
    document.write(unescape("%3Cscript src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js' type='text/javascript'%3E%3C/script%3E"));
}
</script> 
<script src="<?php echo $this->getSkinUrl('Customerpartner/js/nicEdit-latest.js'); ?>" type="text/javascript"></script>
<script type="text/javascript">
  bkLib.onDomLoaded(function() {
        new nicEditor({fullPanel : true}).panelInstance('description');
        new nicEditor({fullPanel : true}).panelInstance('short_description');
  });
</script>
<script src="<?php echo Mage::getBaseUrl('js').'calendar/calendar.js';?>" type="text/javascript"></script>
<script src="<?php echo Mage::getBaseUrl('js').'calendar/calendar-setup.js';?>" type="text/javascript"></script>
<?php
	$collection = Mage::getModel('sales/order')->getCollection();
	echo $this->getMessagesBlock()->getGroupedHtml();
	$products = $this->getProducts();
	if (isset($_SESSION['new_products_errors'])) {
		$style="";
		$name = (isset($_SESSION['new_products_errors']['name'])) ? $_SESSION['new_products_errors']['name'] : '';
		$description = (isset($_SESSION['new_products_errors']['description'])) ? $_SESSION['new_products_errors']['description'] : '';
		$short_description = (isset($_SESSION['new_products_errors']['short_description'])) ? $_SESSION['new_products_errors']['short_description'] : '';
		$price = (isset($_SESSION['new_products_errors']['price'])) ? $_SESSION['new_products_errors']['price'] : '';
		$weight = (isset($_SESSION['new_products_errors']['weight'])) ? $_SESSION['new_products_errors']['weight'] : '';
		$stock = (isset($_SESSION['new_products_errors']['stock'])) ? $_SESSION['new_products_errors']['stock'] : '';unset($_SESSION['new_products_errors']);
	} 
	else {
		$style="display:block;";
		$name = '';
		$description = '';
		$short_description = '';
		$price = '';
		$weight = '';
		$stock = '';
		$sku = '';
	}
		
	$categories = Mage::getModel('catalog/category')->getCollection()->addAttributeToSelect('*')->addIsActiveFilter();
	$allcatid = array();
	$k=0;
	foreach ($categories as $c) {
	   $allcatid[$k] = $c->getId();
	   $k++;
	}
	$finalcat=array_shift($allcatid);
	
?>
<div class="prdouctbackground">
	<form action="<?php echo $this->getUrl('customer/products/simpleproduct') ?>" enctype="multipart/form-data" method="post" id="form-customer-product-new">
		<fieldset class="group-select" id="hiddendiv" style="<?php echo $style?>">
			<input type="hidden" class="len" name="type_id" id="producttype" value="simple" title="producttype" class="" />
			<input type="hidden" class="len" name="status" id="status" value="2" title="status" class="" />
			<input type="hidden" class="len" name="userid" id="userid" value="<?php echo Mage::getSingleton('customer/session')->getCustomer()->getId();?>" title="id" class="" />
			<input type="hidden"  name="wstoreids" id="wstoreids" value="<?php echo Mage::app()->getStore()->getStoreId(); ?>" title="wstoreids" class="" />
			<input type="hidden" class="len" name="attribute_set_id" id="attribute_set_id" value="4" title="AttributeSetId" class="" />
			<div id="customerpartner-products">
				<h4 class="textcolor"><?php echo Mage::helper('marketplacepartner')->__('Add New Simple Product') ?></h4>
				<table class="tablepostion" >
					<thead><tr><th colspan="2" class="headingbg"><?php echo Mage::helper('marketplacepartner')->__("Product Information");?></th></tr></thead>
					<tbody id="tbodying">
						<input type="hidden"  name="producttypecustom" id="producttypecustom" value="customproductsimple" title="producttypecustom" class="" />
						<tr>
							<td class="tdpadfirst">
								<label for="category" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Product Category') ?>:</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<select id="category" class="myinput-text required-entry widthinput" name="category"   >
									<?php foreach($allcatid as $keycat){?>
											<option value="<?php echo $keycat;?>">
											<?php echo Mage::getModel("catalog/category")->load($keycat)->getName(); ?></option>
									<?php } ?>								
								</select>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="name" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Product Name')?> :</label> 
								<span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<input type="name" class="required-entry widthinput" name="name" id="name" />
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="description" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Description') ?> :</label>
								<span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<textarea name="description" class="required-entry " id="description" rows="5" cols="75" ><?php echo $description?></textarea>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="short_description" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Short description') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<textarea name="short_description" id="short_description" rows="5" cols="75" class="required-entry input-text"><?php echo $short_description?></textarea>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="sku" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('SKU') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<input name="sku" id="sku" class=" required-entry widthinput" />
								<div id="skuavail" ><img src="<?php echo $this->getSkinUrl('customerurlpic/available.png'); ?>"/><span><?php echo Mage::helper('marketplacepartner')->__('SKU Available') ?></span></div>
								<div id="skunotavail" ><img src="<?php echo $this->getSkinUrl('customerurlpic/x-mark.jpg'); ?>"/><span><?php echo Mage::helper('marketplacepartner')->__('SKU Already Exist') ?></span></div>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="price" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Price') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<input type="price" class=" required-entry widthinput" name="price" id="price" value="<?php echo $price?>"/>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="stock" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Stock') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<input type="stock" class=" required-entry widthinput" name="stock" id="stock" value="<?php echo $stock?>"/>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="weight" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Weight') ?> :</label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<input type="weight" class=" required-entry widthinput" name="weight" id="weight" value="<?php echo $weight?>"/>
							</td>
						</tr>
						<tr>
							<td class="tdpadfirst">
								<label for="file" class="rightgap"><?php echo Mage::helper('marketplacepartner')->__('Image') ?></label><span class="required starimp">&nbsp;&nbsp;&nbsp;&nbsp;</span>
							</td>
							<td class="tdpadsec">
								<input type="file" name="images" size="33" ><br clear="all"/>
								<a href="#" onClick="showOtherImage(); return false;"><?php echo Mage::helper('marketplacepartner')->__('Add other image') ?></a><br />
								<div id="otherimages"></div>
							</td>
						</tr>						
					</tbody>	
				</table>	
			</div>
			<div class="button-set buttonarea">
				<p class="headingbackindex">
					<a href="javascript:;" onclick="javascript: window.history.back();" class="left">&laquo; <?php echo Mage::helper('marketplacepartner')->__('Back') ?></a>
				</p>
				<center>
					
					<button type="submit" class="form-button btn"><span><?php echo Mage::helper('marketplacepartner')->__('Save') ?></span></button>
					<button type="reset" class="form-button btn"><span><?php echo Mage::helper('marketplacepartner')->__('Cancel') ?></span></button>
				</center>				
			</div>
		</fieldset>
		</form>
</div>		
<!--
end new product
-->
<script> 
jQuery.noConflict();
	jQuery('input#sku').change(function(){
		var len=jQuery('input#sku').val();
		var len2=len.length;
		if(len2==0){
			alert("SKU can't be left empty");
			jQuery('div#skuavail').css('display','none');
			jQuery('div#skunotavail').css('display','none');
		}
		else{
			jQuery.ajax({
				url: "<?php echo Mage::getUrl('customer/products/verifysku');?>",
				type: "POST",
				data: {sku:jQuery('input#sku').val()},
				dataType: 'html',
				success:function($data){//alert(content);
					$data=JSON.parse($data);
					if($data.avl==1){
						jQuery('div#skuavail').css('display','block');
						jQuery('div#skunotavail').css('display','none');
					}
					else{
						jQuery('div#skunotavail').css('display','block');
						jQuery('div#skuavail').css('display','none');
						jQuery("input#sku").attr('value','');
					}
				}
			});
		}
	});
</script>	
<script type="text/javascript">
	var newCustomerProductForm = new VarienForm('form-customer-product-new', true);

	var i=2;
	function showOtherImage(){
		var newdiv = document.createElement('div');
		newdiv.setAttribute("id","childDiv"+i);
		newdiv.innerHTML = "<input type='file' name='images"+i+"' /><a href=\"javascript:;\" onclick=\"removeEvent('childDiv"+i+"')\"><?php echo Mage::helper('marketplacepartner')->__('Remove') ?></a>";
		var ni = document.getElementById('otherimages');
		ni.appendChild(newdiv);
		i++;
	}
	function removeEvent(divNum){
		var d = document.getElementById('otherimages');
		var olddiv = document.getElementById(divNum);
		d.removeChild(olddiv);
		i--;
	}
</script>
<?php }else{
	echo "<h2 style='color:#ff0000;font-weight:600'>".Mage::helper('marketplacepartner')->__("FOR BECOME SELLER CONTACT TO ADMIN")."..</h2>";
}?>

